package Ptolemaiosz;

import java.awt.*;
import java.util.ArrayList;

public class GraphicalElement{
	protected PhysicalEntity physicalEntity;
	protected String textureId;
	protected LevelPartGraphicalEntity levelPartGraphicalEntity;

	protected void draw(Graphics graphics)
            {
                //Megfelelo kasztolas, valamiert kell
                Graphics2D g2 = (Graphics2D)graphics;
                
                        //Az elem poligonjanak lekerese
                        ArrayList<Vector> vertexes  = physicalEntity.getPolygon().getVertexes();
                        
                        //Kirajzolando poligon letrehozasa
                        Polygon canvasPolygon = new Polygon();
                       
                        //Kirajzolando polygon feltoltese, at transzformalt elemekkel
                            for(int j = 0; j < vertexes.size();j++)
                                {
                                    Vector displayVector = new Vector();
                                        displayVector.add(vertexes.get(j)); //Hozzaadjuk a csucsot
                                        displayVector.add(physicalEntity.position); //Hozzadjuk a kozeppontot, igy a palyaszakszon belul mar abszolut lesz
                                        
                                        //Mas a koordinata rendszer at kell konvertalni
                                        displayVector.setY(100.0f - displayVector.getY());
                                        
                                        //Fel kell skalazni az uj meretre
                                            float widthFactor  = levelPartGraphicalEntity.getViewPort().get(2)  / 100.0f;
                                            float heightFactor = levelPartGraphicalEntity.getViewPort().get(3) / 100.0f;

                                            displayVector.setX(displayVector.getX() * widthFactor);
                                            displayVector.setY(displayVector.getY() * heightFactor);
                                                
                                        //el kell tolni a megfelelo pozicioba a kepet
                                        displayVector.add(new Vector(levelPartGraphicalEntity.getViewPort().get(0), levelPartGraphicalEntity.getViewPort().get(1)));
                                            
                                    //Majd belerakni a vegleges poligonba
                                    canvasPolygon.addPoint((int) displayVector.getX(),(int) displayVector.getY());
                                }
                        
                        //Ki kell rajzolni a vegleges poligont  
                        g2.drawImage(TextureManager.getTexture(textureId),canvasPolygon.xpoints[3],canvasPolygon.ypoints[3], canvasPolygon.xpoints[1] - canvasPolygon.xpoints[0],canvasPolygon.ypoints[1] - canvasPolygon.ypoints[2], null);
        
            }

	public void setPhysicalEntity(PhysicalEntity physicalEntity) {
		this.physicalEntity = physicalEntity;
	}

	public void setTextureId(String s) {
		textureId = s;
	}

	public LevelPartGraphicalEntity getLevelPartGraphicalEntity() {
		return this.levelPartGraphicalEntity;
	}

	public void setLevelPartGraphicalEntity(LevelPartGraphicalEntity levelPartGraphicalEntity) {
		this.levelPartGraphicalEntity = levelPartGraphicalEntity;
	}
}